package com.IntelligentCommunity.community.service.impl;

import com.IntelligentCommunity.common.security.utils.SecurityUtils;
import com.IntelligentCommunity.community.domain.DeployVehicles;
import com.IntelligentCommunity.community.domain.RealVehicles;
import com.IntelligentCommunity.community.mapper.RealVehiclesMapper;
import com.IntelligentCommunity.community.service.IRealVehiclesService;
import com.IntelligentCommunity.es.api.RemoteEsMatchingDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 实有车辆信息Service业务层处理
 *
 * @author IntelligentCommunity
 * @date 2024-07-21
 */
@Service
public class RealVehiclesServiceImpl implements IRealVehiclesService
{
    @Autowired
    private RealVehiclesMapper realVehiclesMapper;

    @Autowired
    private RemoteEsMatchingDataService remoteEsMatchingDataService;

    /**
     * 查询实有车辆信息
     *
     * @param id 实有车辆信息主键
     * @return 实有车辆信息
     */
    @Override
    public RealVehicles selectRealVehiclesById(Long id)
    {
        return realVehiclesMapper.selectRealVehiclesById(id);
    }

    /**
     * 查询实有车辆信息列表
     *
     * @param realVehicles 实有车辆信息
     * @return 实有车辆信息
     */
    @Override
    public List<RealVehicles> selectRealVehiclesList(RealVehicles realVehicles)
    {
        return realVehiclesMapper.selectRealVehiclesList(realVehicles);
    }

    /**
     * 新增实有车辆信息
     *
     * @param realVehicles 实有车辆信息
     * @return 结果
     */
    @Override
    public int insertRealVehicles(RealVehicles realVehicles)
    {
        return realVehiclesMapper.insertRealVehicles(realVehicles);
    }

    /**
     * 修改实有车辆信息
     *
     * @param realVehicles 实有车辆信息
     * @return 结果
     */
    @Override
    public int updateRealVehicles(RealVehicles realVehicles)
    {
        return realVehiclesMapper.updateRealVehicles(realVehicles);
    }

    /**
     * 批量删除实有车辆信息
     *
     * @param ids 需要删除的实有车辆信息主键
     * @return 结果
     */
    @Override
    public int deleteRealVehiclesByIds(Long[] ids)
    {
        return realVehiclesMapper.deleteRealVehiclesByIds(ids);
    }

    /**
     * 删除实有车辆信息信息
     *
     * @param id 实有车辆信息主键
     * @return 结果
     */
    @Override
    public int deleteRealVehiclesById(Long id)
    {
        return realVehiclesMapper.deleteRealVehiclesById(id);
    }

    /**
     * 功能：车辆一键布控
     * @param deployVehicles
     */
    @Override
    public void vehiclesAdd(DeployVehicles deployVehicles) {
        // 实有工具类获取当前用户id
        Long userId = SecurityUtils.getUserId();
        deployVehicles.setUseId(userId);
        Integer i = realVehiclesMapper.vehiclesAdd(deployVehicles);
        if(i<0){
            throw new RuntimeException("布控失败");
        }
    }

    /**
     * 功能：车辆一键布控查询
     * @param deployVehicles
     * @return
     */
    @Override
    public List<DeployVehicles> getDeployList(DeployVehicles deployVehicles) {
        List<DeployVehicles> list = realVehiclesMapper.getDeployList(deployVehicles);
        return list;
    }

    /**
     * 功能：编辑车辆布控
     * @param deployVehicles
     * @return
     */
    @Override
    public int deployUpdate(DeployVehicles deployVehicles) {
        return realVehiclesMapper.deployUpdate(deployVehicles);
    }

    /**
     * 功能：车辆一键布控 撤控
     * @param id
     * @return
     */
    @Override
    public int updateStatus(Long id) {
        if(id!=null){
            return realVehiclesMapper.updateStatus(id);
        }
        return 0;
    }

    /**
     * 功能：车辆一键布控 开始
     * @param id
     * @return
     */
    @Override
    public int start(Long id) {
        if(id!=null){
            return realVehiclesMapper.start(id);
        }
        return 0;
    }

    /**
     * 功能：车辆一键布控结束
     * @param id
     * @return
     */
    @Override
    public int stop(Long id) {
        if(id!=null){
            return realVehiclesMapper.stop(id);
        }
        return 0;
    }

    @Override
    public void insertRealVehiclesList(List<RealVehicles> list) {
        realVehiclesMapper.insertRealVehiclesList(list);
    }

    /**
     * 功能：删除车辆一键布控
     * @param id
     * @return
     */
    @Override
    public int deployDelete(Long id) {
        if(id!=null){
            return realVehiclesMapper.deployDelete(id);
        }
        return 0;
    }

    @Override
    public List<DeployVehicles> getDeployLists(DeployVehicles deployVehicles) {
        return realVehiclesMapper.getDeployLists(deployVehicles);
    }

    /**
     * 功能：车辆一键布控暂停
     * @param id
     * @return
     */
    @Override
    public int suspend(Long id) {
        if(id!=null){
            return realVehiclesMapper.suspend(id);
        }
        return 0;
    }
}
